<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Aboutus extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/Admin/aboutus
	 *	- or -  
	 * 		http://example.com/Admin/aboutus/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/Admin/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->aboutus();
	}
	
	public function aboutus()
	{
		$data['current_page'] = "aboutus";
		$db_data = $this->tdatabase->get_entry('aboutus');
		if (isset($db_data)) {
			$db_data = $db_data[0];
			$data['text'] = $db_data->text;
			$data['img'] = $db_data->img;
		}
		$this->parser->parse("admin/header.tpl", $data);
		$this->parser->parse("admin/aboutus.tpl", $data);
		$this->parser->parse("admin/footer.tpl", $data);
	}
	
    public function uploadImage($collID)
	{
        $this->images->upload($collID);
	}
    
	public function save()
	{
		//validate form input
		$this->form_validation->set_rules('text', 'Text', 'required');
		if ($this->form_validation->run() == true)
		{ // check to see if the form was filled properly
			$inputs['id'] = 1;
			$inputs['text'] = $this->input->post('text');
			$this->tdatabase->update_entry($inputs, 'aboutus');
		} else {  // form was not filled properly
			//set the flash data error message if there is one
			$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
		}
		$this->aboutus();
	}

	public function __construct()
	{
		parent::__construct();
		$this->load->library('ion_auth');
		$this->load->library(array('encrypt', 'form_validation', 'session'));
		$this->load->model('tdatabase_model', 'tdatabase');
        $this->load->model('content_images_model', 'images');// LOAD HELPERS
        
		$this->load->helper(array('form'));
		if (!$this->ion_auth->logged_in()) {
			redirect(site_url('auth'));
		}
	}
}

/* End of file Admin.php */
/* Location: ./application/controllers/Admin.php */
